﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Sims3Package.Wrapper
{
    public class TextResourceWrapper : Wrapper
    {
        /// <summary>
        /// Wrapper for text resource
        /// </summary>
        public new static List<UInt32> ResourceTypes { get { return new List<UInt32>(mResourceTypes); } }
        private new static UInt32[] mResourceTypes = { 0x024A0E52U, 0x025C90A6U, 0x025C95B6U, 0x029E333BU, 0x02C9EFF2U,
                                          0x024A0E52U, 0x02FAC0B6U, 0x0333406CU, 0x03B33DDFU, 0x0604ABDAU,
                                          0x0A98EAF0U, 0x1F886EADU, 0x2B6CAB5FU, 0x67771F5CU, 0x73E93EEBU,
                                          0xA8D58BE5U, 0xD4D9FBE5U, 0xDD3223A7U, 0xDD6233D6U, 0xE5105066U,
                                          0xE5105067U, 0xE5105068U, 0xF0FF5598U};

        public TextResourceWrapper(Stream s)
            : base(s)
        {
            stream = s; Parse();
        }

        private void Parse()
        {
            if (stream == null || stream.Length < 1) return;
            stream.Position = 0;
            BinaryReader r = new BinaryReader(stream);
            byte[] data = r.ReadBytes((int)stream.Length);
            this.mValue = Encoding.UTF8.GetString(data);
            
        }

        public override Stream UnParse()
        {
            byte[] data = Encoding.UTF8.GetBytes(this.mValue);
            MemoryStream s = new MemoryStream(data);
            s.Position = 0;
            return s;
        }

        public override string Value { get { return mValue; } }
        [WrapperVisible(true)]
        public string Text { get { return mValue; } set { mValue = value; } }
        
    }
}
